package com.example.ole.taskqueue.Q.base;

public abstract class PrioritizedRunnable implements Runnable, Comparable<PrioritizedRunnable> {
    private int majorPriority;
    private long minorPriority; //minor priority is designed for the paused normal video task who will be requeued, so this normal task has higher priority than the younger one.

    public PrioritizedRunnable(int majorPriority) {
        this(majorPriority, 0);
    }

    public PrioritizedRunnable(int majorPriority, long minorPriority) {
        this.majorPriority = majorPriority;
        this.minorPriority = minorPriority;
    }

    @Override
    public int compareTo(PrioritizedRunnable o) {
        if (this.majorPriority == o.majorPriority) {
            return (int) (this.minorPriority - o.minorPriority);
        } else {
            return -(this.majorPriority - o.majorPriority); //negative is to revert priority for adapting dvrcore requirements, event has higher priority than normal.
        }
    }
}
